import 'dart:io';
import 'package:shared_preferences/shared_preferences.dart';

class StorageUtil {
  static SharedPreferences? _preferences;
  static bool _preinit=false;

  // get string
  static Future<String> getString(String key, {String defValue = ''}) async {
    if (!Platform.isAndroid) {
      return '';
    }
    if(!_preinit){
      _preferences=await SharedPreferences.getInstance();
      _preinit=true;
    }
    return _preferences?.getString(key) ?? defValue;
  }

  // put string
  static putString(String key, String value) async {
    if (!Platform.isAndroid) {
      return;
    }
    if(!_preinit){
      _preferences=await SharedPreferences.getInstance();
      _preinit=true;
    }
    if (_preferences.runtimeType == Null) throw 'not init preferences';
    _preferences?.setString(key, value);
  }
}
